/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.myapp.struts.controleur;

import com.myapp.struts.modele.QueryBD;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

/**
 *
 * @author jackson
 */
public class DetailsEnsAction extends Action {

    /**
     *
     * @param mapping
     * @param form
     * @param request
     * @param response
     * @return
     * @throws Exception
     */
    @Override
    public ActionForward execute(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        
        DetailsEnsForm f = (DetailsEnsForm) form;
        HttpSession session = request.getSession();

        QueryBD qb = (QueryBD) session.getAttribute("bd");

        System.out.println(f.getNum());
        
        
        for (int i = 0; i < qb.getEtudiant().getMatieres().size(); i++) {
                    
                    if(qb.recupAbsenceEns(f.getNum(), qb.getEtudiant().getMatieres().get(i))){
                        
                        //System.out.println(qb.getEtudiant().getMatieres().get(i).getAbsence().get(qb.getEtudiant()).getNbTotalAbsence());
                        
                        session.setAttribute("detailAbsence", qb.getEtudiant().getMatieres().get(i));
                        return mapping.findForward("detailAbsence");   
                    }
                }
            request.setAttribute("message", "module introuvable");
            return mapping.findForward("erreur");
        }
    }
